import { _decorator, Component, Node } from "cc";
const { ccclass, property } = _decorator;

@ccclass("Bg")
export class Bg extends Component {
  @property(Node)
  bg01: Node = null;

  @property(Node)
  bg02: Node = null;

  @property
  speed = 100;

  start() {}

  update(deltaTime: number) {
    const position1 = this.bg01.position;
    this.bg01.setPosition(
      position1.x,
      position1.y - this.speed * deltaTime,
      position1.z
    );

    const position2 = this.bg02.position;
    this.bg02.setPosition(
      position2.x,
      position2.y - this.speed * deltaTime,
      position2.z
    );

    if (this.bg01.position.y < -852) {
      this.bg01.setPosition(
        position1.x,
        this.bg02.position.y + 852,
        position1.z
      );
    }

    if (this.bg02.position.y < -852) {
      this.bg02.setPosition(
        position2.x,
        this.bg01.position.y + 852,
        position2.z
      );
    }
  }
}
